UnityでScreen shotを撮影したい
実行しなくてもログは出るけど実行しないと動作しないので注意
code:ScreenshotTools.cs
using UnityEngine;
using System;
using System.IO;
using UnityEditor;
/**
* 実行時のみ有効。実行していなければ動かしてもスクショは保存されない
*/
public class ScreenshotTools
{
public static void CaptureScreenshot()
{
string productName = Application.productName;
if (string.IsNullOrEmpty(productName))
{
productName = "Unity";
}
string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
productName);
DateTime now = DateTime.Now;
string fileName = string.Format("{0}_{1}x{2}_{3}{4:D2}{5:D2}{6:D2}{7:D2}{8:D2}.png",
productName,
Screen.width,
Screen.height,
now.Year,
now.Month,
now.Day,
now.Hour,
now.Minute,
now.Second);
string path = Path.Combine(directory, fileName);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
ScreenCapture.CaptureScreenshot(path);
Debug.LogFormat("Screenshot Save : {0}", path);
}
}